﻿using Marknic.TestRunner.Rigging;
using NetduinoHappyHour.Hardware;
using System;

namespace NetduinoHappyHour.Util
{
    
    /// <summary>
    /// This is a test class for SystemConfig and is intended
    /// to contain all SystemConfig Unit Tests
    /// Written by: Salvador Richter
    /// Appache License Version 2.0 
    /// </summary>
    public class SystemConfigTest
    {

        /// <summary>
        ///A test for simple pin registration
        ///</summary>
        public void TestRegisterPin()
        {
            SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin0, "test0");
            try
            {
                SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin0, "test99");
            }
            catch (Exception Ex)
            {
                Assert.IsTrue(Ex.Message.Contains("pin 0"));
                Assert.IsTrue(Ex.Message.Contains("test0"));
            }

        }

        /// <summary>
        ///A test for double pin registration, should throw exception
        ///</summary>
        public void TestExRegisterPin()
        {
            SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin1, "test1");
            // this action throws an exception
            SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin1, "test1");
        }

        /// <summary>
        ///A test for pin de- registration
        ///</summary>
        public void TestDeregisterPin()
        {
            // register pin
            SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin2, "test2");
            // deregister pin
            SystemConfig.Instance().DeregisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin2);
            // register pin again, should not throw exception
            SystemConfig.Instance().RegisterPin(Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_Pin2, "test2");
        }
    }
}
